// 递归
function deepClone(obj, hash = new WeakMap()) {
    console.log(obj, '++++');
    if (obj === null) return obj
    if (obj instanceof Date) return new Date(obj)
    if (obj instanceof RegExp) return new RegExp(obj)
    if (typeof obj !== 'object') return obj // 原始值类型
    if (hash.has(obj)) return hash.get(obj)
    let cloneObj = new obj.constructor() // obj是什么类型它就是什么类型
    hash.set(obj, cloneObj) // 处理循环引用
    for (let k in obj) {
        if (obj.hasOwnProperty(k)) {
            cloneObj[k] = deepClone(obj[k], hash)
        }
    }
    return cloneObj
}
let obj1 = {
    // name: 'zzu',
    c: {
        foo: function () {
            return 1
        }
    }
    // list: [1, 2, 1],
    // p: {
    //     height: 10
    // },
}
// let obj2 = {
//     test: obj1
// }
// obj1.test = obj2
let cloneObj = deepClone(obj1)
obj1.foo = 999
console.log(cloneObj);
cloneObj[0] = 10
console.log(obj1);